package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserAddressMapper {
    /**
     * 新增地址
     * @param addressBook
     */
    @Insert("insert into address_book(user_id,consignee,sex,phone,province_code,province_name,city_code,city_name,district_code,district_name,detail,label,is_default)" +
            "values (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void Insert(AddressBook addressBook);

    /**
     * 根据UserId 来查询地址
     * @param userId
     * @return
     */
    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> selectByUserId(Long userId);

    /**
     * 修改地址信息
     * @param address
     */
    void Update(AddressBook address);

    /**
     * 查询默认地址
     * @param addressBook
     * @return
     */
    @Select("select * from address_book where user_id=#{userId} and is_default=#{isDefault} ")
    AddressBook selectDefaultAddress(AddressBook addressBook);

    /**
     * 根据Id来删除
     * @param id
     */
    @Delete("delete from address_book where id=#{id}")
    void DeleteById(Long id);

    /**
     * 根据Id来查询地址
     * @param id
     * @return
     */
    @Select("select *from address_book where id=#{id}")
    AddressBook selectById(Long id);

    /**
     * 修改默认
     * @param address
     */
    @Update("update address_book set is_default=#{isDefault}")
    void UpdateDefault(AddressBook address);
}
